package com.jisf.driver.auth.expression;

import com.jisf.driver.service.impl.UserDetailsImpl;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Classname MyExpressionRoot
 * @Description TODO 自定义权限控制
 * @Date 2022/4/19 16:49
 * @Created by jisf：【429627912@qq.com】
 */
@Component("myExpressionRoot")
public class MyExpressionRoot {

    public boolean hasAuthority(String authority){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
        List<String> permissions = userDetails.getPermissions();
        return permissions.contains(authority);
    }

}
